home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / ODBCINF.PAK / MYSHEET.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  246 lines

  1. // MySheet.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1996 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "OdbcInfo.h"
  16. #include "MySheet.h"
  17. #include "catsets.h"
  18. #include "DrvInfo.h"
  19.  
  20. #include "aboutdlg.h"
  21.  
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. // stolen from afximpl.h...
  29. #define _countof(array) (sizeof(array)/sizeof(array[0]))
  30.  
  31. #define WM_NEW_DSN (WM_USER + 100)
  32. #define USC_DUMPTOFILE    0xEFFF        // user defined sys commands must be < 0xF000
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMyPropertySheet
  36.  
  37. IMPLEMENT_DYNAMIC(CMyPropertySheet, CPropertySheet)
  38.  
  39. CMyPropertySheet::CMyPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  40.     :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  41. {
  42. }
  43.  
  44. CMyPropertySheet::CMyPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  45.     :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  46. {
  47. }
  48.  
  49. CMyPropertySheet::~CMyPropertySheet()
  50. {
  51.     delete m_pbtnDatabase;
  52.     delete m_pchkCursorLib;
  53.     delete m_pbtnAbout;
  54. }
  55.  
  56.  
  57. BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet)
  58.     //{{AFX_MSG_MAP(CMyPropertySheet)
  59.     ON_WM_PAINT()
  60.     ON_WM_ERASEBKGND()
  61.     ON_WM_QUERYDRAGICON()
  62.     ON_WM_SYSCOMMAND()
  63.     ON_WM_INITMENUPOPUP()
  64.     //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CMyPropertySheet message handlers
  69.  
  70. BOOL CMyPropertySheet::OnInitDialog() 
  71. {
  72.  
  73.     // let MFC do it's thing...
  74.     BOOL bRet = CPropertySheet::OnInitDialog();
  75.  
  76.     // ...now we do ours.
  77.     int rgiButtons[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP };
  78.  
  79.     // get the size of one button
  80.     CRect    rect;
  81.     GetDlgItem(rgiButtons[0])->GetWindowRect(&rect);
  82.     CFont* pFont = GetDlgItem(rgiButtons[0])->GetFont();
  83.  
  84.     // remove existing buttons
  85.     for (int i = 0; i < _countof(rgiButtons); i++)
  86.     {
  87.         HWND hWnd = ::GetDlgItem(m_hWnd, rgiButtons[i]);
  88.         if (hWnd != NULL)
  89.         {
  90.             ::ShowWindow(hWnd, SW_HIDE);
  91.             ::EnableWindow(hWnd, FALSE);
  92.         }
  93.     }
  94.  
  95.     // now make our own...
  96.  
  97.     // data source button
  98.     m_pbtnDatabase = new CButton;
  99.     ScreenToClient(&rect);
  100.     int    nDiff = rect.right - rect.left;
  101.     rect.right = nDiff + 6;
  102.     rect.left = 6;
  103.     m_pbtnDatabase->Create(_T("&Data Source"),WS_CHILD | WS_VISIBLE |
  104.         BS_PUSHBUTTON | WS_TABSTOP,rect,this,1001);
  105.     m_pbtnDatabase->SetFont(pFont);
  106.  
  107.     // cursor library check box
  108.     rect.right += nDiff + 106;
  109.     rect.left += nDiff + 6;
  110.     m_pchkCursorLib = new CButton;
  111.     m_pchkCursorLib->Create(_T("&Use Cursor Library"),WS_CHILD | WS_VISIBLE |
  112.         BS_AUTOCHECKBOX | WS_TABSTOP,rect,this,1002);
  113.     m_pchkCursorLib->SetFont(pFont);
  114.     m_pchkCursorLib->SetCheck(1);
  115.  
  116.     // about button
  117.     m_pbtnAbout = new CButton;
  118.     CRect    clientRect;
  119.     GetClientRect(&clientRect);
  120.     rect.right = clientRect.right - 6;
  121.     rect.left = clientRect.right - 6 - nDiff;
  122.     m_pbtnAbout->Create(_T("&About"),WS_CHILD | WS_VISIBLE |
  123.         BS_PUSHBUTTON | WS_TABSTOP,rect,this,1003);
  124.     m_pbtnAbout->SetFont(pFont);
  125.  
  126.     // modify system menu & window styles so we can be
  127.     // minimized and restored
  128.     //
  129.     ModifyStyle(0,WS_MINIMIZEBOX | WS_SYSMENU);
  130.     GetSystemMenu(FALSE)->InsertMenu(1,MF_BYPOSITION,SC_MINIMIZE,
  131.         _T("Mi&nimize"));
  132.     GetSystemMenu(FALSE)->InsertMenu(0,MF_BYPOSITION,SC_RESTORE,
  133.         _T("&Restore"));
  134.     GetSystemMenu(FALSE)->InsertMenu(3,MF_BYPOSITION | MF_SEPARATOR);
  135.     GetSystemMenu(FALSE)->InsertMenu(3,MF_BYPOSITION,USC_DUMPTOFILE,
  136.         _T("&Dump to File"));
  137.     GetSystemMenu(FALSE)->InsertMenu(3,MF_BYPOSITION | MF_SEPARATOR);
  138.  
  139.     return bRet;
  140. }
  141.  
  142. BOOL CMyPropertySheet::OnCommand(WPARAM wParam, LPARAM lParam) 
  143. {
  144.     if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == 1001)
  145.     {
  146.         if (((COdbcInfoApp*)AfxGetApp())->m_Database.IsOpen())
  147.             ((COdbcInfoApp*)AfxGetApp())->m_Database.Close();
  148.         if (m_bCursorLib = m_pchkCursorLib->GetCheck())
  149.             ((COdbcInfoApp*)AfxGetApp())->m_Database.Open(NULL);
  150.         else
  151.             ((COdbcInfoApp*)AfxGetApp())->m_Database.Open(
  152.                 NULL,FALSE,FALSE,"ODBC;",FALSE);
  153.         if (((COdbcInfoApp*)AfxGetApp())->m_Database.IsOpen())
  154.         {
  155.             int nPages = GetPageCount();
  156.             for (int i = 0; i < nPages; i++)
  157.                 ((CMyPage*)GetPage(i))->OnNewDSN();
  158.         }
  159.         return 0;
  160.     }
  161.     else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == 1003)
  162.     {
  163.         CAboutDlg    dlg;
  164.         dlg.DoModal();
  165.         return 0;
  166.     }
  167.  
  168.     return CPropertySheet::OnCommand(wParam, lParam);
  169. }
  170.  
  171. // OnPaint, OnEraseBkgnd, and OnQueryDragIcon supplied so that we
  172. // appear properly when minimized on Windows NT (Not needed for Win95).
  173.  
  174. void CMyPropertySheet::OnPaint() 
  175. {
  176.     CPaintDC dc(this); // device context for painting
  177.     
  178.     if (IsIconic())
  179.     {
  180.         DefWindowProc(WM_ICONERASEBKGND,(WORD)dc.m_hDC,0L);
  181.         CRect    rc;
  182.         GetClientRect(&rc);
  183.         rc.left = (rc.right - ::GetSystemMetrics(SM_CXICON)) >> 1;
  184.         rc.top = (rc.bottom - ::GetSystemMetrics(SM_CYICON)) >> 1;
  185.         HICON    hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  186.         dc.DrawIcon(rc.left,rc.top,hIcon);
  187.     }    
  188.     // Do not call CPropertySheet::OnPaint() for painting messages
  189. }
  190.  
  191. BOOL CMyPropertySheet::OnEraseBkgnd(CDC* pDC) 
  192. {
  193.     if (IsIconic())
  194.         return TRUE;
  195.     return CPropertySheet::OnEraseBkgnd(pDC);
  196. }
  197.  
  198. HCURSOR CMyPropertySheet::OnQueryDragIcon() 
  199. {
  200.     return AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  201. }
  202.  
  203. void CMyPropertySheet::OnSysCommand(UINT nID, LPARAM lParam) 
  204. {
  205.     // menu item will not be enabled if database is not opened
  206.     //
  207.     if (nID == USC_DUMPTOFILE)
  208.     {
  209.         // note: no fancy error handling here
  210.         //
  211.         CFileDialog    dlg(TRUE);
  212.         if (dlg.DoModal() == IDOK)
  213.         {
  214.             CStdioFile    file;
  215.             if (file.Open(dlg.GetPathName(),
  216.                 CFile::typeText | CFile::modeCreate | CFile::modeWrite))
  217.             {
  218.                 if (m_bCursorLib)
  219.                     file.WriteString(_T("Cursor Library is Loaded\n\n"));
  220.                 else
  221.                     file.WriteString(_T("Cursor Library is Not Loaded\n\n"));
  222.                 int nPages = GetPageCount();
  223.                 for (int i = 0; i < nPages; i++)
  224.                     ((CMyPage*)GetPage(i))->DumpToFile(file);
  225.                 file.Close();
  226.             }
  227.             else
  228.                 AfxMessageBox(_T("Could not open output file"));
  229.         }
  230.         return;
  231.     }
  232.     
  233.     CPropertySheet::OnSysCommand(nID, lParam);
  234. }
  235.  
  236. void CMyPropertySheet::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
  237. {
  238.     CPropertySheet::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  239.     
  240.     if (((COdbcInfoApp*)AfxGetApp())->m_Database.IsOpen())
  241.         GetSystemMenu(FALSE)->EnableMenuItem(4,MF_BYPOSITION | MF_ENABLED);
  242.     else
  243.         GetSystemMenu(FALSE)->EnableMenuItem(4,MF_BYPOSITION | MF_GRAYED);
  244.     
  245. }
  246.